package com.congee02.bt.dfs.top2bottom;

import com.congee02.bt.TreeNode;

public class GoodNodes {

    public int goodNodes(TreeNode root) {
        return help(root, - 300001);
    }

    private int help(TreeNode root, int max) {

        if (root == null) {
            return 0;
        }

        int cur = 0;
        if (root.val >= max) {
            max = root.val;
            cur = 1;
        }

        return cur + help(root.left, max) + help(root.right, max);
    }

}
